package com.cleaningcloud.erp.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.cleaningcloud.common.core.utils.poi.ExcelUtil;
import com.cleaningcloud.erp.domain.vo.ErpAccountsPayableVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cleaningcloud.common.log.annotation.Log;
import com.cleaningcloud.common.log.enums.BusinessType;
import com.cleaningcloud.common.security.annotation.RequiresPermissions;
import com.cleaningcloud.erp.domain.ErpAccountsPayable;
import com.cleaningcloud.erp.service.IErpAccountsPayableService;
import com.cleaningcloud.common.core.web.controller.BaseController;
import com.cleaningcloud.common.core.web.domain.AjaxResult;
import com.cleaningcloud.common.core.web.page.TableDataInfo;

/**
 * 应付账款Controller
 * 
 * @author cleaningcloud
 * @date 2024-09-30
 */
@RestController
@RequestMapping("/ErpAccountsPayable")
public class ErpAccountsPayableController extends BaseController
{
    @Autowired
    private IErpAccountsPayableService erpAccountsPayableService;

    /**
     * 查询应付账款列表
     */
    @RequiresPermissions("erp:ErpAccountsPayable:list")
    @GetMapping("/list")
    public TableDataInfo list(ErpAccountsPayable erpAccountsPayable)
    {
        startPage();
        List<ErpAccountsPayableVo> list = erpAccountsPayableService.selectErpAccountsPayableList(erpAccountsPayable);
        return getDataTable(list);
    }

    /**
     * 导出应付账款列表
     */
    @RequiresPermissions("erp:ErpAccountsPayable:export")
    @Log(title = "应付账款", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ErpAccountsPayable erpAccountsPayable)
    {
        List<ErpAccountsPayableVo> list = erpAccountsPayableService.selectErpAccountsPayableList(erpAccountsPayable);
        ExcelUtil<ErpAccountsPayableVo> util = new ExcelUtil<ErpAccountsPayableVo>(ErpAccountsPayableVo.class);
        util.exportExcel(response, list, "应付账款数据");
    }

    /**
     * 获取应付账款详细信息
     */
    @RequiresPermissions("erp:ErpAccountsPayable:query")
    @GetMapping(value = "/{payableId}")
    public AjaxResult getInfo(@PathVariable("payableId") Long payableId)
    {
        return success(erpAccountsPayableService.selectErpAccountsPayableByPayableId(payableId));
    }

    /**
     * 新增应付账款
     */
    @RequiresPermissions("erp:ErpAccountsPayable:add")
    @Log(title = "应付账款", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErpAccountsPayable erpAccountsPayable)
    {
        return toAjax(erpAccountsPayableService.insertErpAccountsPayable(erpAccountsPayable));
    }

    /**
     * 修改应付账款
     */
    @RequiresPermissions("erp:ErpAccountsPayable:edit")
    @Log(title = "应付账款", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErpAccountsPayable erpAccountsPayable)
    {
        return toAjax(erpAccountsPayableService.updateErpAccountsPayable(erpAccountsPayable));
    }


    /**
     * 应付账款付款
     */
    @RequiresPermissions("erp:ErpAccountsPayable:pay")
    @Log(title = "应付账款付款", businessType = BusinessType.UPDATE)
    @PutMapping("/pay")
    public AjaxResult pay(@RequestBody ErpAccountsPayable erpAccountsPayable)
    {
        return toAjax(erpAccountsPayableService.paymentErpAccountsPayable(erpAccountsPayable));
    }


    /**
     * 删除应付账款
     */
    @RequiresPermissions("erp:ErpAccountsPayable:remove")
    @Log(title = "应付账款", businessType = BusinessType.DELETE)
	@DeleteMapping("/{payableIds}")
    public AjaxResult remove(@PathVariable Long[] payableIds)
    {
        return toAjax(erpAccountsPayableService.deleteErpAccountsPayableByPayableIds(payableIds));
    }


    /**
     * 获取应付账款顶部统计
     */
    @GetMapping(value = "/statistics")
    public AjaxResult statistics()
    {
        return success(erpAccountsPayableService.statistics());
    }
}
